
let common = {
    Width: $(window).width(),
    Height: $(window).height(),
    scrollTop: null,
    WowJsAnimation: null,
    //导航判断
    IfNav: false,
    fzlcPerView: 4,
    casePerView: 3,
    partPerView: 6,
    indexPerView: 1,
    fzlcSwiper: null,
    caseSwiper: null,
    partSwiper: null,
    //有锚点才吸顶
    maoTop: false,
    //锚点距离
    maoNumber: 0,
    MaxSwiper: null,
    indexBanner: null,
    SwiperFadeIn: 'fade',
    SwiperLoop: 'loop',
    init: function () {
        let _this = this;
        _this.addEventLit()
        _this.WowJs()
        _this.NavScroll();
    },
    //动画启动
    WowJs: function () {
        this.WowJsAnimation = new WOW({
            animateClass: 'animated',
            offset: 50
        });
        this.WowJsAnimation.init();
    },
    addEventLit: function () {
        let _this = this;
        function return_false() {
            return false;
        }
        $('.m-header-nav').on('click', function (e) {
            e.preventDefault();
            if (!_this.IfNav) {
                $('html,body, .black-box').on('mousewheel DOMMouseScroll wheel', return_false);
                $('.m-header-nav span:first-child').removeClass('first-rotate2').addClass('first-rotate');
                $('.m-header-nav span:last-child').removeClass('last-rotate2').addClass('last-rotate');
                $('.m-header-nav span:nth-child(2)').removeClass('navOpacity2').addClass('navOpacity');
                $('.m-header-nav').addClass('header-click-nav');
                $('.header-nav ul li').removeClass('headerScale').addClass('headerScale');
                $('.black-box').stop();
                $('.black-box').fadeIn();
                _this.IfNav = true;
            } else {
                $('html,body, .black-box').off('mousewheel DOMMouseScroll wheel', return_false);
                $('.m-header-nav span:first-child').removeClass('first-rotate').addClass('first-rotate2');
                $('.m-header-nav span:last-child').removeClass('last-rotate').addClass('last-rotate2');
                $('.m-header-nav span:nth-child(2)').removeClass('navOpacity').addClass('navOpacity2');
                $('.m-header-nav').removeClass('header-click-nav');
                $('.header-nav ul li').addClass('headerScale').removeClass('headerScale');
                $('.black-box').stop();
                $('.black-box').fadeOut();
                _this.IfNav = false;
            }
        });
    },
    //获取TOP
    NavScroll: function () {
        let that = this;
        that.scrollTop = $(window).scrollTop();

        that.NavScrollTop();
        $(window).scroll(function () {
            that.NavScrollTop();
        });
    },
    //判断top值
    NavScrollTop: function () {
        let that = this;
        that.scrollTop = $(window).scrollTop();
        //大于导航的高度
        if (that.scrollTop > 115) {
            $('.header-wrap').addClass('header-wrap2');
            // $(".header-nav ul li").removeClass("header-hover-nav")
        } else {
            $('.header-wrap').removeClass('header-wrap2');
        }
        // let ReadImgH = $('#banner').height() - 75;
        let ReadImgH = $('#banner').height() - $(".header-wrap").height();
        if (that.scrollTop > ReadImgH) {
            if (ReadImgH > 0) {
                $('.read-mbx-nav').addClass('mbx-nav-fixed');
            }
        } else {
            if (ReadImgH > 0) {
                $('.read-mbx-nav').removeClass('mbx-nav-fixed');
            }
        }

    },
    fzlcTab: function () {
        let that = this;
        if (that.Width < 1200) {
            that.fzlcPerView = 1;
        }
        that.fzlcSwiper = new Swiper('.fzlc-swiper', {
            slidesPerView: that.fzlcPerView,
            initialSlide: 0,
            centeredSlides: false,//居中
            loop: true,
            spaceBetween: 0,
            loopAdditionalSlides: 100,
            observer: true,
            observeParents: false,
            navigation: {
                nextEl: '.fzlc-swiper-prev',
                prevEl: '.fzlc-swiper-next',
            },
        });
    },
    caseTab: function () {
        let that = this
        if (that.Width < 1200) {
            that.casePerView = 1;
        }
        that.caseSwiper = new Swiper(".case-swiper", {
            slidesPerView: that.casePerView,
            initialSlide: 0,
            centeredSlides: false,//居中
            loop: false,
            spaceBetween: 0,
            loopAdditionalSlides: 100,
            observer: true,
            observeParents: false,
            navigation: {
                nextEl: '.case-swiper-next',
                prevEl: '.case-swiper-prev',
            },
        })
    },
    partTab: function () {
        let that = this;
        if (that.Width < 1200) {
            that.partPerView = 3;
        }
        that.partSwiper = new Swiper(".gallery-swiper", {
            slidesPerView: that.partPerView,//一行显示3个
            slidesPerColumn: 2,//显示2行
            centeredSlides: false,//居中
            loop: false,
            spaceBetween: 0,
            loopAdditionalSlides: 100,
            observer: true,
            observeParents: false,
            navigation: {
                nextEl: '.gallery-swiper-next',
                prevEl: '.gallery-swiper-prev',
            },
        })
    },
    //内导航吸顶
    aboutNav: function () {
        let that = this;
        let top = $(window).scrollTop();
        let aReadNav = $('.read-mbx-nav ul li');
        let aCurrent = $('.read-select');
        let aClass = 'mbx-hover';
        for (let i = 0; i < aCurrent.length - 1; i++) {
            if ((top + 1) >= aCurrent.eq(i).offset().top && top < aCurrent.eq(i + 1).offset().top) {
                aReadNav.eq(i).addClass(aClass).siblings().removeClass(aClass);
            }
        }
        if (top > aCurrent.eq(aCurrent.length - 1).offset().top) {
            aReadNav.eq(aCurrent.length - 1).addClass(aClass).siblings().removeClass(aClass);
        }

        $(window).scroll(function () {
            let top = $(window).scrollTop() + (Math.abs(that.maoNumber) + 1);
            let aCurrent = $('.read-select');
            for (let i = 0; i < aCurrent.length - 1; i++) {
                if ((top + 1) >= aCurrent.eq(i).offset().top && top < aCurrent.eq(i + 1).offset().top) {
                    aReadNav.eq(i).addClass(aClass).siblings().removeClass(aClass);
                }
            }
            if (top > aCurrent.eq(aCurrent.length - 1).offset().top) {
                aReadNav.eq(aCurrent.length - 1).addClass(aClass).siblings().removeClass(aClass);
            }
        })

    },
    //锚点特效
    maoAnimate: function () {
        let that = this;
        that.maoTop = true;
        that.aboutNav();
        //锚点滑动
        $('.about-mao').click(function () {
            let $target = $(this.hash);
            $target = $target.length && $target || $('[name=' + this.hash.slice(1) + ']');
            if ($target.length) {
                let targetOffset = $target.offset().top;
                $('html,body').animate({
                    scrollTop: targetOffset + that.maoNumber
                },
                    700);
                return false;
            }
        });
    },
    //max大图
    MaxTab: function () {
        let that = this;
        that.MaxSwiper = new Swiper('.swiper-max-box', {
            loop: that.SwiperLoop,

        });
    },
    //max点击预览
    ClickMaxImg: function () {
        let that = this;
        let MaxImgLable = $('.pro-img-li');
        //图集左右按钮
        $(".swiper-max-prev").on('click', function (e) {
            e.preventDefault();
            that.MaxSwiper.slideNext();
        });
        $('.swiper-max-next').on('click', function (e) {
            e.preventDefault();
            that.MaxSwiper.slidePrev();
        });

        $('.swiper-max-button').on('click', function (e) {
            e.preventDefault();
            that.MaxSwiper = null;
            $('.swiper-max-wrap').fadeOut();
            $('.swiper-max-list').fadeOut();
        });

        $(".pro-img-min").on('click', MaxImgLable, function (e) {
            e.preventDefault();
            console.log(MaxImgLable.index(this));
            $('.swiper-max-wrap').fadeIn();
            $('.swiper-max-list').fadeIn();
            that.MaxTab();
            that.MaxSwiper.slideTo(MaxImgLable.index(this) + 1);

        });
    },
    caseHover: function () {
        $(".solution-case").hover(function (e) {
            console.log(e.target)
            $(this).find("img").attr("src", "../imgs/add.png")
        })
    },
    // 获取banner
    getBanner: function (sign) {
        let _this = this;
        ajax_get(host + `/ajax/banner/${sign}`,
            true,
            {},
            (res) => {
                res = JSON.parse(res)
                console.log("banner", res)
                console.log(_this.Width)
                if (sign == 'index') {
                    if (res.length > 0) {
                        let str = ''
                        res.forEach((item, index) => {
                            let curClass = "banner-txt banner-index"
                            if (index == 1) {
                                curClass = "banner-txt banner-index curIndex1"
                            } else if (index == 2) {
                                curClass = "banner-txt banner-index curIndex2"
                            } else if (index == 3) {
                                curClass = "banner-txt banner-index curIndex3"
                            } else if (index == 4) {
                                curClass = "banner-txt banner-index curIndex4"
                            } else if (index == 5) {
                                curClass = "banner-txt banner-index curIndex5"
                            }
                            if (parseInt(_this.Width) < 1200) {
                                str += `<div class="swiper-slide">
                            <a href="${item.to_url}">
                                <img src="${item.background_m}" alt="${item.to_title}" class="banner-img">
                            </a>
                            <div class="${curClass}">
                                <div class="banner-btn fadeInLeft2">
                                    <a href="${item.to_url}">Learn More</a>
                                </div>
                            </div>
                        </div>`
                            } else {
                                str += `<div class="swiper-slide">
                            <a href="${item.to_url}">
                                <img src="${item.background}" alt="${item.to_title}" class="banner-img">
                            </a>
                            <div class="${curClass}">
                                <div class="banner-btn fadeInLeft2">
                                    <a href="${item.to_url}">Learn More</a>
                                </div>
                            </div>
                        </div>`
                            }

                        })
                        $(".banner-boxs").html(str)
                        _this.BannerSwiper()
                    }
                } else {
                    if (res.background) {
                        $(".banner-img").attr("src", res.background)
                    }
                }
            },
            err => {
                console.log(err)
            }
        );
    },
    getConfigInfo: function () {
        ajax_get(host + '/ajax/config',
            true,
            {},
            (res) => {
                res = JSON.parse(res)
                console.log(res)
                if (res.site_name) {
                    $(".footer-copyright").text(res.site_name + res.site_copyright + res.site_beian)
                }
            },
            err => {
                console.log(err)
            }
        );
    },
    getPhoneInfo: function () {
        ajax_get(host + '/ajax/contact',
            true,
            {},
            (res) => {
                res = JSON.parse(res)
                console.log(res)
                $(".footer-right .company").text("深圳市楚邦科技有限公司")
                $(".footer-right .phone").text("电话：" + res.phone2)
                $(".footer-right .email").text("邮箱：" + res.email)
                $(".footer-right .adress").text("地址：" + res.address )
            },
            err => {
                console.log(err)
            }
        );
    },
    getFootProductCatList: function () {
        ajax_get(host + `/ajax/productsCate`,
            true,
            {},
            (res) => {
                res = JSON.parse(res)
                let str = ''
                if (res && res.length > 0) {
                    res.forEach((item, index) => {
                        str += ` <li>
                            <a href="product.html?cateId=${item.id}">${item.name}</a>
                        </li>`
                    })
                }
                $(".footer-product-ul").html(str)
            },
            err => {
                console.log(err)
            }
        );
    },
    getFootInfo:function(){
        ajax_get(host + '/ajax/index',
            true,
            {},
            (res) => {
                res = JSON.parse(res)
                if (res.background) {
                    console.log(res)
                    const { project, solution } = res;
                    
                    let solutionStr = ""
                    if(solution && solution.length > 0){
                        solution.forEach((item, index) => {
                            solutionStr += `<li>
                            <a href="solution-detail.html?id=${item.id}">${item.title}</a>
                            </li>`
                        })
                        $(".foot-solution-ul").html(solutionStr)
                    }
                    let caseStr = ""
                    if(project && project.length > 0){
                        project.forEach((item, index) => {
                            caseStr += `<li>
                            <a href="case-detail.html?id=${item.id}">${item.title}</a>
                            </li>`
                        })
                        // $(".foot-cases-ul").html(caseStr)
                    }
                }
            },
            err => {
                console.log(err)
            }
        );
    },
    getQueryString: function (name) {
        let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        let r = window.location.search.substr(1).match(reg);
        if (r != null) {
            return unescape(r[2]);
        };
        return null;
    },
    indexSwiper: function () {
        let that = this;
        that.indexSwipers = new Swiper(".banner-container", {
            slidesPerView: that.indexPerView,//一行显示3个
            centeredSlides: false,//居中
            loop: true,
            spaceBetween: 0,
            loopAdditionalSlides: 100,
            observer: true,
            observeParents: false,
            navigation: {
                nextEl: '.banner-next',
                prevEl: '.banner-prev',
            },
        })
    },
    //banner
    BannerSwiper: function () {
        this.indexBanner = new Swiper('.banner-box', {
            effect: this.SwiperFadeIn,
            loop: this.SwiperLoop,
            slidesPerView: 'auto',
            autoplay: {
                delay: 5000,
                stopOnLastSlide: false,
                disableOnInteraction: true,
            },
            fadeEffect: {
                crossFade: true,
            },
            pagination: {
                el: '.banner-box .swiper-pagination',
                clickable: true,
            },
            loopedSlides: document.querySelectorAll('.swiper-slide').length,
            on: {
                init: function () {
                    let that = this;
                    // $('.swiper-text-box .swiper-animation').removeClass('fadeInLeft2');
                    // $('.swiper-text-box1 .swiper-animation').addClass('fadeInLeft2');

                    //加入下标
                    for (let j = 0; j < this.loopedSlides; j++) {
                        $('.swiper-pagination2').append('<span class="en1"></span>');
                        $('.swiper-pagination2 span').eq(j).html('0' + (j + 1));

                    }
                    $('.swiper-pagination2 span').eq(0).addClass('slide-opacity').siblings().removeClass('slide-opacity');
                    $('.swiper-pagination2 span').on('click', function () {
                        that.slideTo($(this).index());
                        // $('.swiper-text-box .swiper-animation').removeClass('fadeInLeft2');
                        // $('.swiper-text-box' + ($(this).index() + 1) + '').children('.swiper-animation').addClass('fadeInLeft2');
                        $(this).addClass('slide-opacity').siblings().removeClass('slide-opacity');
                    });
                },
                slideChangeTransitionEnd: function () {
                    if (this.activeIndex == (this.loopedSlides - 1)) {
                        // $('.swiper-slide .swiper-text-box .swiper-animation').removeClass('fadeInLeft2');
                        // $('.swiper-text-box' + this.loopedSlides + ' .swiper-animation').addClass('fadeInLeft2');
                        //加入下标
                        $('.swiper-pagination2 span').eq(this.loopedSlides - 1).addClass('slide-opacity').siblings().removeClass('slide-opacity');
                    }
                    if (this.activeIndex == (this.loopedSlides * 2)) {
                        // $('.swiper-slide .swiper-text-box .swiper-animation').removeClass('fadeInLeft2');
                        // $('.swiper-text-box1 .swiper-animation').addClass('fadeInLeft2');
                        //加入下标
                        $('.swiper-pagination2 span').eq(0).addClass('slide-opacity').siblings().removeClass('slide-opacity');
                    }
                    for (let i = 0; i < this.loopedSlides; i++) {
                        if ((this.activeIndex - this.loopedSlides) == i) {
                            // $('.swiper-slide .swiper-text-box .swiper-animation').removeClass('fadeInLeft2');
                            // $('.swiper-text-box' + (i + 1) + ' .swiper-animation').addClass('fadeInLeft2');
                            //加入下标
                            $('.swiper-pagination2 span').eq(i).addClass('slide-opacity').siblings().removeClass('slide-opacity');
                            break;
                        }
                    }
                },
            },
        });
    },
}